import BaseMapper from "./BaseMapper";
import SqlStatement from "../sql/SqlStatement";
import SystemMember from "../entity/SystemMember";
import SystemLoyalty from "../entity/SystemLoyalty";

export default class SystemLoyaltyMapper implements BaseMapper<SystemLoyalty> {
    async deleteById(statement: SqlStatement) {
        return await statement.run();
    }

    async insert(statement: SqlStatement) {
        return await statement.run();
    }

    async page(statement: SqlStatement) {
        const rows = await statement.all();
        const total = await statement.count();
        return {
            rows,
            total: total.counter
        }
    }

    async updateById(statement: SqlStatement) {
        return await statement.run();
    }

    async selectByMemberId(memberId: string) {
        const sql = `SELECT * FROM system_loyalty WHERE memberid = '${memberId}'`;
        const statement = new SqlStatement(sql);
        const rows = await statement.get();
        return rows;
    }
}
